package pers.lls.hds.sort.partition;

/**
 * 二分排序  stream无序
 *
 * @author lilichai
 */
public class PartitionSort {

    long[] arr = {1, 3, 5, 2, 6, 9, 8, 7, 4};
    int size = 0;

    public int partitionIt(int left, int right, long pivot) {
        int leftPtr = left - 1;
        int rightPtr = right + 1;
        while (true) {
            while (leftPtr < right && arr[++leftPtr] < pivot) {
                ;
            }

            while (rightPtr > left && arr[--rightPtr] > pivot) {
                ;
            }
            if (leftPtr >= rightPtr) {
                break;
            } else {
                swap(leftPtr, rightPtr);
            }
        }
        return leftPtr;
    }

    public void swap(int dex1, int dex2) {
        long temp;
        temp = arr[dex1];
        arr[dex1] = arr[dex2];
        arr[dex2] = temp;
    }

    public static void main(String[] args) {
        PartitionSort partitionSort = new PartitionSort();
    }

}
